package com.ffyc.resale.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ffyc.resale.model.Chat;
import com.ffyc.resale.model.Comment;
import com.ffyc.resale.model.Result;
import com.ffyc.resale.service.ChatService;
import com.ffyc.resale.util.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/chat")
public class ChatController {
    @Autowired
    ChatService chatService;

    @PostMapping("/getChatList")
    public Result getChatList(@RequestHeader String userToken){
        List<Chat> chatList = chatService.getChatList(userToken);
        return new Result(200,"查询成功",chatList);
    }
    @GetMapping("/chatRecord")
    public Result chatRecord(@RequestHeader String userToken,Integer id){
        List<Chat> recordList = chatService.chatRecord(userToken,id);
        return new Result(200,"查询成功",recordList);
    }
    @PostMapping("/createChat")
    public Result createChat(@RequestBody Chat chat,@RequestHeader String userToken){
        Integer id = JWTUtil.id(userToken);
        chatService.createChat(chat,id);
        return new Result(200,"成功",null);
    }
    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize,
                             @RequestParam("content") String content){
        System.out.println("---------------------------------------");
       Page<Chat> page= chatService.selectPage(pageNum,pageSize,content);
       return new Result(200,"成功",page);
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        chatService.deleteById(id);
        return new Result(200,"成功",null);
    }
}
